<?php
class SubForum extends AppModel {
	public $name = 'SubForum';
	public $tablePrefix = 'cakeforum_';
	public $belongsTo = array('Forum');
	public $hasMany = array('Thread');

	public $validate = array(
		'name' => array(
			'required1' => array(
				'rule' => 'notEmpty',
				'message' => 'Please enter a forum name'
			),
			'required2' => array(
				'rule' => 'isUnique',
				'message' => 'A forum with this name already exists'
			)
		),
		'role' => array(
			'required3' => array(
				'rule' => 'notEmpty',
				'message' => 'Please select a role'
			),
			'required4' => array(
				'rule' => array('inList', array('1','2','3')),
				'message' => 'Invalid role'
			)
		),
		'description' => array(
			'required5' => array(
				'rule' => 'notEmpty',
				'message' => 'Please enter a description'
			)
		),
		'searchquery' => array(
			'required1' => array(
				'rule' => array('minLength' => 4),
				'message' => 'Please enter 4 or more characters'
			)
		)
	);

	public function canPostHere($id = null){
		$subForumRole = $this->field('role', array('id' => $id));
		return (AuthComponent::User('role') >= $subForumRole);
	}
}